package com.work.straighttalk;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.widget.Button;

import com.work.straighttalk.app.BaseActivity;
import com.work.straighttalk.app.StraightTalk;
import com.work.straighttalk.bean.User;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.listener.FindListener;

/**
 * Created by dllo on 16/3/15.
 */
public class FriendsCircleActivity extends BaseActivity {
    @Bind(R.id.friends_circle_recyclerView)
    RecyclerView friendsCircleRecyclerView;
    @Bind(R.id.publish_btn)
    Button publishBtn;
    private FriendsCircleAdapter adp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_friends_circle);
        ButterKnife.bind(this);

        adp = new FriendsCircleAdapter();
        friendsCircleRecyclerView.setLayoutManager(new GridLayoutManager(this, 1));
        friendsCircleRecyclerView.setAdapter(adp);


        BmobQuery<FriendsTexts> query = new BmobQuery<FriendsTexts>();
        query.findObjects(this, new FindListener<FriendsTexts>() {
            @Override
            public void onSuccess(List<FriendsTexts> object) {
                // TODO Auto-generated method stub
                adp.addData(object);
            }

            @Override
            public void onError(int code, String msg) {
                // TODO Auto-generated method stub
                toast("查询失败：" + msg);
            }
        });
    }

    @OnClick(R.id.publish_btn)
    protected void toEditACtivity() {
        startActivity(EditActivity.class, null, false);
    }

    @Override
    protected void onResume() {
        super.onResume();

        User user = BmobUser.getCurrentUser(this, User.class);
        BmobQuery<FriendsTexts> query = new BmobQuery<FriendsTexts>();
        query.findObjects(this, new FindListener<FriendsTexts>() {
            @Override
            public void onSuccess(List<FriendsTexts> object) {
                // TODO Auto-generated method stub
                adp.addData(object);
            }

            @Override
            public void onError(int code, String msg) {
                // TODO Auto-generated method stub
                toast("查询失败：" + msg);
            }
        });

    }
}
